package com.liner;

import java.util.Arrays;
import java.util.Random;

public class ArrayDemo {
    public static void main(String[] args) {


        Random random = new Random();
        int i1 = random.nextInt(100);//0~99
        //生成10~50
        int i2 = random.nextInt(41) + 10;//0~40 -> 10~50
        System.out.println(i1);
        System.out.println(i2);

        int[] ints1 = new int[12];
        for (int i = 0; i < ints1.length; i++) {
            ints1[i] = (int) (Math.random() * 100);
            System.out.print(ints1[i] + "\t");
        }
        System.out.println("\n********************");

        Arrays.sort(ints1);
        for (int i : ints1) {
            System.out.print(i + "\t");
        }

        System.out.println("\n********************");

        for (int i = ints1.length - 1; i >= 0; i--) {
            System.out.print(ints1[i] + "\t");
        }

        System.out.println("\n********************");


        int[] i = new int[12];
        double[] doubles = new double[12];
        boolean[] booleans = new boolean[23];

        System.out.println(i.length);
        System.out.println(doubles.length);
        System.out.println(booleans.length);


        int[] ints = new int[]{123, 431, 542212, 51};
        for (int anInt : ints) {
            System.out.print(anInt + "\t");
        }


        System.out.println("\n~~~~~~~~~~~~~~~~~");


        int[] arr = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
        for (int j = 0; j < arr.length; j++) {
            System.out.print(arr[j] + "\t");
        }
        System.out.println("\n++++++++++++");

        for (int j : arr) {
            System.out.print(j + "\t");
        }

        //ArrayIndexOutOfBoundsException 数组下标越界异常
        //System.out.println(arr[12]);

        System.out.println("\n~~~~~~~~~~");

        double[] array = new double[5];
        for (int j = 0; j < array.length; j++) {
            array[j] = Math.random() * 100;
            System.out.print(array[j] + "\t");
        }

        for (double v : array) {
            System.out.print(v + "\t");
        }

        System.out.println("\n~~~~~~~~~~");


    }
}
